package 复合模式;

/**
 * @author zzs
 * @ClassName Demo.java
 * @Description 适配
 * @createTime 2022年05月21日 10:06:00
 */
public class Demo {
    public static void main(String[] args) {
        // 普通创建方式
//        Duck oneGoose = new GooseAdapter(new OneGoose());
//        OneDuck oneDuck = new OneDuck();
//        DuckQuackCount duckQuackCount = new DuckQuackCount(oneDuck);
//        print(oneGoose);
//        print(duckQuackCount);
//        print(duckQuackCount);
//        print(duckQuackCount);
//        print(duckQuackCount);
        // 工厂模式封装了创建对象的方式
//        OneDuckFactory oneDuckFactory = new OneDuckFactory();
//        Duck duck = oneDuckFactory.createdDuck();
//        print(duck);
//        Duck duck1 = oneDuckFactory.createdDuckCount();
//        print(duck1);
//        print(duck1);
//        print(duck1);
//        print(duck1);
//        print(duck1);
//        System.out.println(DuckQuackCount.count);
        // 观察者模式观察某一群鸭子
        DuckObservable duckObservable = new DuckObservable();
//        OneDuck oneDuck3 = new OneDuck(duckObservable);
//        oneDuck3.quack();
//        oneDuck3.quack();
//        oneDuck3.quack();
//        duckObservable.notifyObserver();
        // 观察者+工厂模式观察某一群鸭子
        OneDuckFactory oneDuckFactory = new OneDuckFactory();
        for (int i = 0; i < 10; i++) {
            Duck duck = oneDuckFactory.createdDuckObserver(duckObservable);
            duck.quack();
        }
        duckObservable.notifyObserver();
    }

    static void print(Duck duck) {
        // 利用多态的机制
        duck.quack();
    }
}
